// 暂存
import {
    toast,
    promptBox
} from 'nc-lightapp-front';
import stagingSaveData from '../request/stagingSaveData';
import init from './init';
import language from '../../../language';
export default async function (func_type = 1, pageId = 600704) {
    let {
        // 存储了新增页面的模版
        addPageTemplate,
        // 人力资源组织信息
        humanResourceOrganizationValue,
        // 从哪个页面跳转过来
        pageFrom,
        form,
        imageData,
        selectedRows,
        meta
    } = this.props;

    let allTableData = this.getAllTableData();

    let postData = {
        ...allTableData,
        CurrentPkPsndoc: addPageTemplate.Pk_psncl || null,
        InJobType: addPageTemplate.InJobType || 'hire',
        func_type: func_type,
        pk_org: humanResourceOrganizationValue.refpk,
        ui_state: pageFrom === 'add' ? 1 : 2,
        ui_temp: 1,
        bd_psndoc: form.getAllFormValue('bd_psndoc'),
        hi_psnjob_h: form.getAllFormValue('hi_psnjob_h'),
        hi_psnorg_h: form.getAllFormValue('hi_psnorg_h'),
        image: imageData
    };
    postData.bd_psndoc.rows[0].values.dr.value = "1";

    let clerkcodeValue = postData.hi_psnjob_h.rows[0].values.clerkcode.value;
    let pk_orgValue = postData.hi_psnjob_h.rows[0].values.pk_org.value;
    if (!clerkcodeValue) {
        toast({
            color: 'danger',
            content: language['hi6007-000311'] || '员工号不能为空'
        });
        return false
    } else if (!pk_orgValue) {
        toast({
            color: 'danger',
            content: language['hi6007-000312'] || '请填写组织'
        });
        return false
    }
    console.log('暂存测试', postData)
    let res = await stagingSaveData(postData); 
    if (res.success) {
        if(res.data.errMsg){
            toast({
                color: 'danger',
                content: res.data.errMsg
            });
            return false
        }
        toast({
            color: 'success',
            content: language['hi6007-000313'] || '暂存成功'
        });
        this.props.updateState({
            pk_psnjob: res.data['pk_psnjob']
        })
        this.props.getModifyData((res) => {
            init.call(this, true);
            this.props.cancelEdit();
        }, res.data['pk_psnjob'], 'refresh');
    }
} 